<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#include "../common/header.ftl">
    <script>
        $(function () {
            $('.showBtn').click(function () {
                //获取文章内容
                var id = $(this).data("tid");
                $.get("/travel/getContentById.do",{id:id},function (data) {
                    $(".modal-body").html(data.content);
                    $("#inputModal").modal("show");
                });
            });
            //修该状态
            $('.changeStateBtn').click(function () {
                var id = $(this).data("tid");
                var state = $(this).data("state");
                $.get("/travel/changeState.do",{id:id,state:state},function (data) {
                    if(data.success){
                        location.reload();
                    }
                });
            });
            //推荐游记
            $(".commendBtn").click(function () {
                //1:先清空模态框的数据,再来做操作
                $("#commendModal input").val("");
                //2:获取当前按钮中的自定义JSON对象
                var obj = $(this).data("json");
                //3:只有编辑按钮才做数据回显
                if (obj) {
                    //把游记id设置到游记推荐表单的隐藏域中
                    $("#commendModal input[name='travelId']").val(obj.id);
                    $("#commendModal input[name='title']").val(obj.title);
                    $("#commendModal input[name='coverUrl']").val(obj.coverUrl);
                    $("#coverImg").attr('src',obj.coverUrl);
                }
                $("#commendModal").modal('show');
            });
            $("#editForm").ajaxForm(function(data) {
                //操作成功刷新界面
                if (data.success) {
                    location.reload();
                } else {
                    //操作失败,提交用户错误信息
                    $.messager.alert("温馨提示", data.msg);
                }
            });

            //模态框的表单提交
            $(".submitBtn").click(function() {
                $("#editForm").submit();
            });
        });
    </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl">
    <div class="row">
        <div class="col-sm-3">
            <#include "../common/menu.ftl">
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">已发布游记管理</h1>
                </div>
            </div>
        <#--高级查询--->
            <form class="form-inline" id="searchForm" action="/travelRelease/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
            </form>
            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>封面</th>
                    <th>作者</th>
                    <th>地区</th>
                    <th>状态</th>
                    <th></th>
                </tr>
                <#list pageInfo.list as entity>
                    <tr>
                       <td>${entity_index + 1}</td>
                       <td>${entity.title}</td>
                       <td>
                        <img src="${entity.coverUrl}" width="30px">
                        </td>
                        <td>${entity.author.nickName}</td>
                        <td>${(entity.place.name)!}</td>
                        <td>
                           <#if entity.state=-1>
                               拒绝
                               <#elseif entity.state=0>
                                草稿
                               <#elseif entity.state=1>
                                待发布
                               <#elseif entity.state=2>
                                已发布
                           </#if>
                        </td>
                        <td>
                            <a href="javascript:" class="btn btn-info btn-xs showBtn" data-tid="${entity.id}">
                                <span class="glyphicon glyphicon-pencil"></span> 查看内容
                            </a>
                            <a href="javascript:" class="btn btn-warning btn-xs changeStateBtn" data-state="1" data-tid="${entity.id}">
                                <span class="glyphicon glyphicon-leaf"></span> 取消发布
                            </a>
                            <a href="javascript:" class="btn btn-primary  btn-xs commendBtn"  data-json='${entity.json}'>
                                <span class="glyphicon glyphicon-tag"></span> 推荐
                            </a>
                        </td>

                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl">
        </div>
    </div>
</div>
<#--模态框必须是body的子元素-->
<div class="modal fade" id="commendModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        <#--模态框标题-->
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">查看内容</h4>
            </div>
        <#--模态框正文-->
            <div class="modal-body">
            <#--填充编辑界面-->
                <form class="form-horizontal" action="/travelCommend/saveOrUpdate.do" method="post" id="editForm" enctype="multipart/form-data">
                    <input type="hidden" name="travelId"/>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="title" placeholder="请输入标题"/>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">副标题：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="subTitle" placeholder="请输入副标题"/>
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-lg-4 control-label">封面：</label>
                        <div class="col-lg-6">
                            <img  id="coverImg" width="100%"> <!--用来显示-->
                            <input type="hidden" class="form-control" name="coverUrl" /><!--用来提交表单(回显)-->
                            <input type="file" class="form-control" name="file" /><!--用来提交表单(上传)-->
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">推荐时间：</label>
                        <div class="col-lg-6">
                            <input type="text" class="form-control" name="schedule" onclick="WdatePicker()" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-4 control-label">推荐类型：</label>
                        <div class="col-lg-6">
                            <select name="type" class="form-control">
                                <option value="1">每周推荐</option>
                                <option value="2">每月推荐</option>
                                <option value="3">攻略推荐</option>
                            </select>
                        </div>
                    </div>
                </form>

            </div>
        <#--模态框底部按钮-->
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary submitBtn">保存</button>
            </div>
        </div>
    </div>
</div>
<#--查看内容-->
<div class="modal fade" id="inputModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title">查看内容</h4>
            </div>
            <div class="modal-body">
            </div>
        </div>
    </div>
</div>
</body>
<style>
    #inputModal img{
        width: 100%;
    }

    #inputModal .modal-body{
        max-height: 600px;
        overflow-y: auto;
    }
</style>
</body>
</html>